<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>文档管理</title>
    <link rel="stylesheet" type="text/css" href="/static/css/base.css">
    <script src="/static/js/frame/checkout.js"></script>
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script src="/static/js/frame/checkout.js"></script>
    <script>
        function sort_link(str){
            // 获取当前URL  
            var currentUrl = window.location.href;  
            // 提取查询参数部分  
            var queryString = window.location.search;  
            // 更新URL  
            console.log(queryString);
            if (queryString == ''){
                window.location.href = currentUrl + '?order=' + str + '&asc=DESC';
            }else{
                queryString = queryString.replace('?','');
                var obj = stringToObject(queryString);
                console.log(obj);
                obj.order = str;
                if (!obj.asc || obj.asc == 'asc') {
                    obj.asc = "desc";
                }else{
                    obj.asc = "asc";
                }
                newQueryString = Object.entries(obj).map(([key, value]) => `${key}=${value}`).join('&');
                console.log(newQueryString);
                window.location.href = currentUrl.replace(queryString,newQueryString);
            }
        }
        function delKeyword(){
            var aid = '',j = 0;
            var ids = document.getElementsByName('id');
            console.log(ids);
            for(let i = 0; i < ids.length; i++) {
                console.log(ids[i].value);
                if (isInteger(ids[i].value)){
                    aid += '&keyword[' + j + ']=' + ids[i].value;
                    j++;
                }
            }
            url = '/admin/keyword/del?' + aid;
            console.log(url);
            const is_bool = get_url_data(url);
            console.log(is_bool);
            if(is_bool == "OK"){
                alert('删除成功');
                location.reload();
            }else{
                alert('删除失败');
            }
        }
    </script>
    <style>
        tr:nth-child(1) th a:link{
            color: aliceblue;
        }
        .layui-icon{
            border-radius: 10px;
        }
    </style>
</head>
<body leftmargin="8" topmargin="8" background='/static/images/allbg.gif'>
    <div class="x-nav">
        <span class="layui-breadcrumb">
          <a href="">首页</a>
          <a href="">演示</a>
          <a>
            <cite>导航元素</cite></a>
        </span>
        <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
          <i class="layui-icon" style="line-height:38px">ဂ</i></a>
      </div>
      <div class="x-body">
        <div class="layui-row">
          <form class="layui-form layui-col-md12 x-so">
            <input class="layui-input" placeholder="关键词" name="keyword">
            <!-- <div class="layui-input-inline">
              <select name="status">
                <option value="0">全部</option>
                <option value="1">未补完</option>
                <option value="2">未支付</option>
              </select>
            </div> -->
            <!-- <input type="text" name="username"  placeholder="请输入订单号" autocomplete="off" class="layui-input"> -->
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
          </form>
        </div>
        <xblock>
          <!-- <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
          <button class="layui-btn" onclick="x_admin_show('添加用户','/admin/goods/info/0.html')"><i class="layui-icon"></i>添加</button> -->
          <span class="x-right" style="line-height:40px">共有数据：{$list->total()}条</span>
        </xblock>
        <form action="" name="form2">
                <table class="layui-table">
                    <thead>
                        <tr bgcolor="#FAFAF1">
                            <th height="28" colspan="8">
                                <a href="javascript:selAll()" class="layui-btn">全选</a>
                                <a href="javascript:noSelAll()" class="layui-btn">取消</a>
                                <!-- <a href="javascript:updateArc(0)" class="coolbg">&nbsp;更新&nbsp;</a> -->
                                <a href="javascript:addKeyword();" class="layui-btn">&nbsp;新增&nbsp;</a>
                                <a href="javascript:delKeyword();" class="layui-btn">&nbsp;删除&nbsp;</a>
                            </th>
                        </tr>
                        <tr align="center" bgcolor="#FAFAF1" height="22">
                            <th>
                                
                            </th>
                            <th><a id="keyword" href="javascript:sort_link('keyword',this);" style="display: block;">关键词</a></th>
                            <th><a id="price" href="javascript:sort_link('price',this);" style="display: block;">价格</a></th>
                            <th><a id="pc" href="javascript:sort_link('pc',this);" style="display: block;">数据</a></th>
                            <th><a id="keywords" href="javascript:sort_link('keywords',this);" style="display: block;">相关关键词</a></th>
                            <th><a id="start_time" href="javascript:sort_link('start_time',this);" style="display: block;">数据截取时间</a></th>
                            <th><a id="update_time" href="javascript:sort_link('update_time',this);" style="display: block;">更新时间</a></th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="value"}
                    <tr>
                        <td><input name="id" type="checkbox" value="{$value.keyword}" class="np"></td>
                        <td><u>{$value.keyword}</u></td>
                        <td>
                            <div>全端:{$value.price}</div>
                            <div>电脑:{$value.pc_price}</div>
                            <div>移动:{$value.phone_price}</div>
                        </td>
                        <td>
                            <div>
                                电脑端:{$value.pc|default=0}
                            </div>
                            <div>
                                移动端:{$value.phone|default=0}
                            </div>
                        </td>
                        <td><a href="javascript:;" onclick="showkeywords('{$value.keywords|default=''}')">查看详情</a></td>
                        <td>{$value.start_time|default=''} - {$value.end_time|default=''}</td>
                        <td>{$value.update_time}</td>
                        <td><a href="javascript:updKeyword('{$value.keyword}');">更新</a></td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </form>
        <div class="page">{$list|raw}</div>
    </div>
</body>
<script>
    window.onload = function(){
        var queryString = window.location.search;  
        if (queryString != ''){
            queryString = queryString.replace('?','');
            var obj = stringToObject(queryString);
            if (obj.order){
                if (!obj.asc || obj.asc == 'asc') {
                    document.getElementById(obj.order).style = 'background-color: aquamarine;display:block;';
                }else{
                    document.getElementById(obj.order).style = 'background-color: chartreuse;display:block;';
                }
            }
            if(obj.keyword){
                document.getElementsByName('keyword')[0].value = obj.keyword;
            }
        }
    }
</script>
</html>